package com.example.zengpengcheng0526;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;


public class OneFragment extends Fragment {

    List<ShangPin> splist;
    ListAdapter adapter;
    int[] imgi={R.drawable.tou3,R.drawable.tou5,R.drawable.tou9,R.drawable.tou10,R.drawable.tou11,R.drawable.tou12};
    public OneFragment(){
        init();
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_one, container, false);
        ListView tv=view.findViewById(R.id.lv);

        adapter=new ListAdapter(splist,inflater);
        tv.setAdapter(adapter);
        return view;
    }
    public void init(){
        splist=new ArrayList<>();
        for (int i = 0; i <30 ; i++) {
            ShangPin sp=new ShangPin();
            sp.setName("商品"+i);
            sp.setImg(imgi[i%6]);
            sp.setJianjie(i+".很长很长很长很长很长很长很长很长很长的简介");
            sp.setPrice(55.0+i);
            splist.add(sp);
        }

    }

}
